package com.baosight.sczx.common.zm.upload;

import java.io.FileOutputStream;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import com.baosight.iplat4j.upload.fileUploadHandler;

public class FileHandler implements fileUploadHandler {

	@SuppressWarnings("unused")
	private String oldName;
	@SuppressWarnings("unused")
	private String newName;
	/**
	 * 该函数用来处理对文件保存路径的处理，如果需要处理则返回要处理的值，否则返回null
	 * <p>Function: handleFilePath</p>
	 * <p>Description: </p>
	 * <p>return value: FileHandler</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2010-12-17上午09:57:35 张志芳
	 * </p>
	 *
	 */
	@SuppressWarnings("rawtypes")
	public String handleFilePath(HttpServletRequest request, Map result, String fileFolder, String fileName) 
	{
		oldName = fileName;
		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddkkmmss");
		fileName = fileName.substring(0, fileName.lastIndexOf("."))+"_"+sdf.format(new Date())+fileName.substring(fileName.lastIndexOf("."));
		newName = fileName;
		return fileName;
	}

	/**
	 * 该函数提供文件上传完毕后的流信息的处理
	 * <p>Function: handleStream</p>
	 * <p>Description: </p>
	 * <p>return value: FileHandler</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2010-12-17上午09:57:50 张志芳
	 * </p>
	 *
	 */
	@SuppressWarnings("rawtypes")
	public boolean handleStream(HttpServletRequest request, Map result,FileOutputStream fileStream) {
//		HttpSession session = request.getSession();
//		EiInfo inInfo = new EiInfo();
//		ZMCD05 zmcd05 = new ZMCD05();
//		inInfo.addBlock("result").addBlockMeta(zmcd05.eiMetadata);
//		Map row = new HashMap();
//		row.put("fdKeyId", TablePk.getInstance().getNextValue("T_CI_FILES"));
//		row.put("fdFileName", oldName);
//		row.put("fdMemoryName", newName);
//		row.put("fdForeignId", session.getAttribute("fileForeignId"));
//		
//		inInfo.getBlock("result").addRow(row);
//		
//		ServiceZMCD05 service = new ServiceZMCD05();
//		EiInfo outinfo = service.insert(inInfo);
//		if(outinfo.getStatus()>0){
//			return true;
//		}
		return true;
	}

}
